package com.tanhua.controller;

import com.tanhua.interceptor.UserHolder;
import com.tanhua.model.dto.RecommendUserDto;
import com.tanhua.model.vo.NearUserVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.TodayBest;
import com.tanhua.server.TanhuaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class TanhuaController {
    @Autowired
    private TanhuaService tanhuaService;


    //今日佳人
    @GetMapping("/todayBest")
    public ResponseEntity todayBest() {
        TodayBest vo = tanhuaService.getBest(UserHolder.getUserId());
        return ResponseEntity.ok(vo);
    }

    //推荐用户列表
    @GetMapping("/recommendation")
    public ResponseEntity<PageResult> fondsFriends(RecommendUserDto recommendUserDto) {
        PageResult pageResult = tanhuaService.recommendation(recommendUserDto);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 查看佳人详情
     */
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity<TodayBest> personalInfo(@PathVariable("id") Long userId) {
        TodayBest todayBest = tanhuaService.findById(userId);
        return ResponseEntity.ok(todayBest);
    }

    /**
     * 查询佳人陌生人问题
     */
    @GetMapping("/strangerQuestions")
    public ResponseEntity<String> getStrangerQuestions(Long userId) {
        String quest = tanhuaService.getStrangerQuestions(userId);
        return ResponseEntity.ok(quest);
    }

    /**
     * 回答陌生人问题
     * @param map
     * @return
     */
    @PostMapping("/strangerQuestions")
    public ResponseEntity<Void> replayStrangerQuestions(@RequestBody Map map) {
        String userId = map.get("userId").toString();
        Long userId1 = Long.valueOf(userId);

        String reply = map.get("reply").toString();
        tanhuaService.replyQuestions(userId1, reply);
        return ResponseEntity.ok(null);
    }


    /**
     * 探花推荐用户
     */
    @GetMapping("/cards")
    public ResponseEntity<List<TodayBest>> queryCardsList() {
        List<TodayBest> todayBestList = tanhuaService.queryCardsList();
        return ResponseEntity.ok(todayBestList);
    }

    /**
     * 探花喜欢
     * @param likeUserId 喜欢的用户
     * @return
     */
    @GetMapping("{id}/love")
    public ResponseEntity<Void> likeUser(@PathVariable(value = "id") Long likeUserId) {
        tanhuaService.likeUser(likeUserId);
        return ResponseEntity.ok(null);
    }

    @GetMapping("{id}/unlove")
    public ResponseEntity<Void> dislikeUser(@PathVariable(value = "id") Long likeUserId) {
        tanhuaService.dislikeUser(likeUserId);
        return ResponseEntity.ok(null);
    }

    /**
     * 附近的人
     * @param gender 性别
     * @param distance 距离(m)
     * @return
     */
    @GetMapping("/search")
    public ResponseEntity<List<NearUserVo>> getNearUser(
            @RequestParam(defaultValue = "woman") String gender,
            @RequestParam(defaultValue = "2000") String distance) {
        List<NearUserVo> nearUserVos = tanhuaService.getNearUser(gender, distance);
        return ResponseEntity.ok(nearUserVos);
    }
}
